package com.ruoyi.web.controller.credit;

import java.util.*;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CreditUserInfo;
import com.ruoyi.system.service.ICreditUserInfoService;

/**
 * 信用商业服务控制器
 * 
 * @author ruoyi
 * @date 2024-01-26
 */
@RestController
@RequestMapping("/credit/businessService")
public class CreditBusinessServiceController extends BaseController
{
    private static final Logger logger = LoggerFactory.getLogger(CreditBusinessServiceController.class);
    
    @Autowired
    private ICreditUserInfoService creditUserInfoService;

    /**
     * 获取用户信用信息
     */
    @PreAuthorize("@ss.hasPermi('credit:businessService:view')")
    @GetMapping("/userCredit")
    public AjaxResult getUserCredit()
    {
        Map<String, Object> userCredit = new HashMap<>();
        userCredit.put("creditScore", 785);
        userCredit.put("creditLevel", "良好");
        userCredit.put("canRent", true);
        userCredit.put("canHotel", true);
        userCredit.put("canGoods", true);
        userCredit.put("discountRate", 15);
        
        return AjaxResult.success(userCredit);
    }

    /**
     * 获取租房服务列表
     */
    @PreAuthorize("@ss.hasPermi('credit:businessService:view')")
    @GetMapping("/rental/list")
    public AjaxResult getRentalList(@RequestParam(required = false) String area,
                                   @RequestParam(required = false) String priceRange)
    {
        try {
            // 从数据库查询房源信息
            String sql = "SELECT room_id, room_title, room_address, room_price, room_area, room_type, " +
                        "room_images, room_desc, required_score, is_available " +
                        "FROM credit_room WHERE is_available = '1'";
            
            List<Map<String, Object>> rentalList = new ArrayList<>();
            
            // 这里应该使用JdbcTemplate或MyBatis查询数据库
            // 为了演示，我们返回模拟的真实数据结构
            Map<String, Object> rental1 = new HashMap<>();
            rental1.put("room_id", 1);
            rental1.put("room_title", "精装两室一厅，采光良好");
            rental1.put("room_address", "市中心CBD核心区域");
            rental1.put("room_price", 3500.00);
            rental1.put("room_area", 85.5);
            rental1.put("room_type", "两室一厅");
            rental1.put("room_images", "[\"https://images.unsplash.com/photo-1560448204-e02f11c3d0e2?w=400&h=300&fit=crop\", \"https://images.unsplash.com/photo-1560448204-603b3fc33ddc?w=400&h=300&fit=crop\"]");
            rental1.put("room_desc", "精装修两室一厅，采光良好，交通便利，配套设施齐全");
            rental1.put("required_score", 700);
            rental1.put("is_available", "1");
            rentalList.add(rental1);
            
            Map<String, Object> rental2 = new HashMap<>();
            rental2.put("room_id", 2);
            rental2.put("room_title", "温馨一室户，拎包入住");
            rental2.put("room_address", "地铁沿线，生活便利");
            rental2.put("room_price", 2200.00);
            rental2.put("room_area", 45.0);
            rental2.put("room_type", "一室户");
            rental2.put("room_images", "[\"https://images.unsplash.com/photo-1560448204-603b3fc33ddc?w=400&h=300&fit=crop\", \"https://images.unsplash.com/photo-1560448204-e02f11c3d0e2?w=400&h=300&fit=crop\"]");
            rental2.put("room_desc", "温馨一室户，拎包入住，地铁沿线，生活便利");
            rental2.put("required_score", 650);
            rental2.put("is_available", "1");
            rentalList.add(rental2);
            
            Map<String, Object> rental3 = new HashMap<>();
            rental3.put("room_id", 3);
            rental3.put("room_title", "豪华三室两厅，景观房");
            rental3.put("room_address", "江景豪宅区");
            rental3.put("room_price", 5800.00);
            rental3.put("room_area", 120.0);
            rental3.put("room_type", "三室两厅");
            rental3.put("room_images", "[\"https://images.unsplash.com/photo-1560448204-e02f11c3d0e2?w=400&h=300&fit=crop\", \"https://images.unsplash.com/photo-1560448204-603b3fc33ddc?w=400&h=300&fit=crop\"]");
            rental3.put("room_desc", "豪华三室两厅，江景房，配套设施齐全");
            rental3.put("required_score", 800);
            rental3.put("is_available", "1");
            rentalList.add(rental3);
            
            return AjaxResult.success(rentalList);
        } catch (Exception e) {
            logger.error("获取房源列表失败", e);
            return AjaxResult.error("获取房源列表失败");
        }
    }

    /**
     * 获取酒店服务列表
     */
    @PreAuthorize("@ss.hasPermi('credit:businessService:view')")
    @GetMapping("/hotel/list")
    public AjaxResult getHotelList(@RequestParam(required = false) String area,
                                  @RequestParam(required = false) String starLevel)
    {
        try {
            // 从数据库查询酒店信息
            String sql = "SELECT hotel_id, hotel_name, hotel_address, hotel_price, hotel_level, " +
                        "hotel_images, hotel_desc, occupancy_rate, required_score, is_available " +
                        "FROM credit_hotel WHERE is_available = '1'";
            
            List<Map<String, Object>> hotelList = new ArrayList<>();
            
            // 这里应该使用JdbcTemplate或MyBatis查询数据库
            // 为了演示，我们返回模拟的真实数据结构
            Map<String, Object> hotel1 = new HashMap<>();
            hotel1.put("hotel_id", 1);
            hotel1.put("hotel_name", "希尔顿酒店");
            hotel1.put("hotel_address", "市中心商务区");
            hotel1.put("hotel_price", 688.00);
            hotel1.put("hotel_level", "五星级");
            hotel1.put("hotel_images", "[\"https://images.unsplash.com/photo-1566073771259-6a8506099945?w=400&h=300&fit=crop\", \"https://images.unsplash.com/photo-1571896349842-33c89424de2d?w=400&h=300&fit=crop\"]");
            hotel1.put("hotel_desc", "五星级酒店，商务设施齐全，服务一流");
            hotel1.put("occupancy_rate", 85.5);
            hotel1.put("required_score", 750);
            hotel1.put("is_available", "1");
            hotel1.put("star", 5.0);
            hotel1.put("tags", Arrays.asList("免押金", "五星级", "商务出行"));
            hotelList.add(hotel1);
            
            Map<String, Object> hotel2 = new HashMap<>();
            hotel2.put("hotel_id", 2);
            hotel2.put("hotel_name", "如家酒店");
            hotel2.put("hotel_address", "火车站附近");
            hotel2.put("hotel_price", 268.00);
            hotel2.put("hotel_level", "经济型");
            hotel2.put("hotel_images", "[\"https://images.unsplash.com/photo-1506744038136-46273834b3fb?w=400&h=300&fit=crop\"]");
            hotel2.put("hotel_desc", "经济型酒店，干净整洁，性价比高");
            hotel2.put("occupancy_rate", 92.3);
            hotel2.put("required_score", 650);
            hotel2.put("is_available", "1");
            hotel2.put("star", 3.0);
            hotel2.put("tags", Arrays.asList("经济实惠", "地铁附近"));
            hotelList.add(hotel2);
            
            Map<String, Object> hotel3 = new HashMap<>();
            hotel3.put("hotel_id", 3);
            hotel3.put("hotel_name", "万豪酒店");
            hotel3.put("hotel_address", "机场附近");
            hotel3.put("hotel_price", 988.00);
            hotel3.put("hotel_level", "五星级");
            hotel3.put("hotel_images", "[\"https://images.unsplash.com/photo-1512918728675-ed5a9ecdebfd?w=400&h=300&fit=crop\"]");
            hotel3.put("hotel_desc", "五星级酒店，机场附近，交通便利");
            hotel3.put("occupancy_rate", 78.9);
            hotel3.put("required_score", 800);
            hotel3.put("is_available", "1");
            hotel3.put("star", 5.0);
            hotel3.put("tags", Arrays.asList("江景房", "免押金"));
            hotelList.add(hotel3);
            
            return AjaxResult.success(hotelList);
        } catch (Exception e) {
            logger.error("获取酒店列表失败", e);
            return AjaxResult.error("获取酒店列表失败");
        }
    }

    /**
     * 获取商品列表
     */
    @PreAuthorize("@ss.hasPermi('credit:businessService:view')")
    @GetMapping("/goods/list")
    public AjaxResult getGoodsList(@RequestParam(required = false) String category,
                                  @RequestParam(required = false) String priceRange)
    {
        try {
            // 从数据库查询商品信息
            String sql = "SELECT goods_id, goods_name, goods_price, goods_category, " +
                        "goods_images, goods_desc, recommend_score, is_recommended, " +
                        "stock_quantity, is_available " +
                        "FROM credit_goods WHERE is_available = '1'";
            
            List<Map<String, Object>> goodsList = new ArrayList<>();
            
            // 这里应该使用JdbcTemplate或MyBatis查询数据库
            // 为了演示，我们返回模拟的真实数据结构
            Map<String, Object> goods1 = new HashMap<>();
            goods1.put("goods_id", 1);
            goods1.put("goods_name", "iPhone 15 Pro");
            goods1.put("goods_price", 7999.00);
            goods1.put("goods_category", "数码电子");
            goods1.put("goods_images", "[\"https://images.unsplash.com/photo-1511707171634-5f897ff02aa9?w=400&h=300&fit=crop\"]");
            goods1.put("goods_desc", "最新款iPhone，性能强劲，信用分750以上专享价");
            goods1.put("recommend_score", 780);
            goods1.put("is_recommended", "1");
            goods1.put("stock_quantity", 50);
            goods1.put("is_available", "1");
            goods1.put("tags", Arrays.asList("分期免息", "信用专享"));
            goodsList.add(goods1);
            
            Map<String, Object> goods2 = new HashMap<>();
            goods2.put("goods_id", 2);
            goods2.put("goods_name", "MacBook Air M2");
            goods2.put("goods_price", 8999.00);
            goods2.put("goods_category", "数码电子");
            goods2.put("goods_images", "[\"https://images.unsplash.com/photo-1517336714731-489689fd1ca8?w=400&h=300&fit=crop\"]");
            goods2.put("goods_desc", "轻薄笔记本，M2芯片，性能出色");
            goods2.put("recommend_score", 800);
            goods2.put("is_recommended", "1");
            goods2.put("stock_quantity", 30);
            goods2.put("is_available", "1");
            goods2.put("tags", Arrays.asList("信用优惠", "正品保证"));
            goodsList.add(goods2);
            
            Map<String, Object> goods3 = new HashMap<>();
            goods3.put("goods_id", 3);
            goods3.put("goods_name", "Nike Air Max 270");
            goods3.put("goods_price", 899.00);
            goods3.put("goods_category", "运动健身");
            goods3.put("goods_images", "[\"https://images.unsplash.com/photo-1519125323398-675f0ddb6308?w=400&h=300&fit=crop\"]");
            goods3.put("goods_desc", "经典跑鞋，舒适透气，信用用户免押金试穿");
            goods3.put("recommend_score", 720);
            goods3.put("is_recommended", "1");
            goods3.put("stock_quantity", 100);
            goods3.put("is_available", "1");
            goods3.put("tags", Arrays.asList("信用分期", "限时优惠"));
            goodsList.add(goods3);
            
            return AjaxResult.success(goodsList);
        } catch (Exception e) {
            logger.error("获取商品列表失败", e);
            return AjaxResult.error("获取商品列表失败");
        }
    }

    /**
     * 获取商品推荐
     */
    @PreAuthorize("@ss.hasPermi('credit:businessService:view')")
    @GetMapping("/goods/recommend")
    public AjaxResult getGoodsRecommend(@RequestParam(required = false) String category)
    {
        try {
            // 从数据库查询推荐商品信息
            String sql = "SELECT goods_id, goods_name, goods_price, goods_category, " +
                        "goods_images, goods_desc, recommend_score, is_recommended, " +
                        "stock_quantity, is_available " +
                        "FROM credit_goods WHERE is_recommended = '1' AND is_available = '1'";
            
            List<Map<String, Object>> recommendations = new ArrayList<>();
            
            // 这里应该使用JdbcTemplate或MyBatis查询数据库
            // 为了演示，我们返回模拟的真实数据结构
            Map<String, Object> rec1 = new HashMap<>();
            rec1.put("goods_id", 4);
            rec1.put("goods_name", "华为Mate 60 Pro");
            rec1.put("goods_price", 6999.00);
            rec1.put("goods_category", "数码电子");
            rec1.put("goods_images", "[\"https://images.unsplash.com/photo-1519125323398-675f0ddb6308?w=400&h=300&fit=crop\"]");
            rec1.put("goods_desc", "华为旗舰手机，性能强劲，拍照出色");
            rec1.put("recommend_score", 780);
            rec1.put("is_recommended", "1");
            rec1.put("stock_quantity", 40);
            rec1.put("is_available", "1");
            rec1.put("reason", "基于您的信用分780分，推荐此款旗舰手机");
            rec1.put("tags", Arrays.asList("信用专享", "旗舰体验"));
            recommendations.add(rec1);
            
            Map<String, Object> rec2 = new HashMap<>();
            rec2.put("goods_id", 5);
            rec2.put("goods_name", "AirPods Pro 2");
            rec2.put("goods_price", 1799.00);
            rec2.put("goods_category", "数码电子");
            rec2.put("goods_images", "[\"https://images.unsplash.com/photo-1517336714731-489689fd1ca8?w=400&h=300&fit=crop\"]");
            rec2.put("goods_desc", "降噪耳机，音质出色，便携性强");
            rec2.put("recommend_score", 720);
            rec2.put("is_recommended", "1");
            rec2.put("stock_quantity", 80);
            rec2.put("is_available", "1");
            rec2.put("reason", "您经常购买数码产品，这款耳机很适合您");
            rec2.put("tags", Arrays.asList("降噪", "信用优惠"));
            recommendations.add(rec2);
            
            Map<String, Object> rec3 = new HashMap<>();
            rec3.put("goods_id", 6);
            rec3.put("goods_name", "戴森V12无线吸尘器");
            rec3.put("goods_price", 3690.00);
            rec3.put("goods_category", "生活用品");
            rec3.put("goods_images", "[\"https://images.unsplash.com/photo-1511707171634-5f897ff02aa9?w=400&h=300&fit=crop\"]");
            rec3.put("goods_desc", "强劲吸力，信用分用户可享分期免息");
            rec3.put("recommend_score", 720);
            rec3.put("is_recommended", "1");
            rec3.put("stock_quantity", 25);
            rec3.put("is_available", "1");
            rec3.put("reason", "信用良好用户专享生活用品优惠");
            rec3.put("tags", Arrays.asList("生活", "信用专享"));
            recommendations.add(rec3);
            
            return AjaxResult.success(recommendations);
        } catch (Exception e) {
            logger.error("获取商品推荐失败", e);
            return AjaxResult.error("获取商品推荐失败");
        }
    }

    /**
     * 申请租房服务
     */
    @PreAuthorize("@ss.hasPermi('credit:businessService:view')")
    @Log(title = "租房服务申请", businessType = BusinessType.INSERT)
    @PostMapping("/rental/apply")
    public AjaxResult applyRental(@RequestBody Map<String, Object> applicationData)
    {
        Integer rentalId = (Integer) applicationData.get("rentalId");
        String userMessage = (String) applicationData.get("message");
        
        // 模拟申请逻辑
        logger.info("用户申请租房服务，房源ID：{}，留言：{}", rentalId, userMessage);
        
        Map<String, Object> result = new HashMap<>();
        result.put("applicationId", "R" + System.currentTimeMillis());
        result.put("status", "pending");
        result.put("message", "申请已提交，房东将在24小时内联系您");
        
        return AjaxResult.success(result);
    }

    /**
     * 预订酒店服务
     */
    @PreAuthorize("@ss.hasPermi('credit:businessService:view')")
    @Log(title = "酒店预订", businessType = BusinessType.INSERT)
    @PostMapping("/hotel/book")
    public AjaxResult bookHotel(@RequestBody Map<String, Object> bookingData)
    {
        Integer hotelId = (Integer) bookingData.get("hotelId");
        String checkInDate = (String) bookingData.get("checkInDate");
        String checkOutDate = (String) bookingData.get("checkOutDate");
        Integer rooms = (Integer) bookingData.get("rooms");
        
        // 模拟预订逻辑
        logger.info("用户预订酒店，酒店ID：{}，入住：{}，退房：{}，房间数：{}", 
                   hotelId, checkInDate, checkOutDate, rooms);
        
        Map<String, Object> result = new HashMap<>();
        result.put("bookingId", "H" + System.currentTimeMillis());
        result.put("status", "confirmed");
        result.put("message", "预订成功，酒店确认信息已发送至您的手机");
        result.put("totalAmount", 776); // 2晚388*2
        result.put("deposit", 0); // 信用免押
        
        return AjaxResult.success(result);
    }

    /**
     * 购买商品
     */
    @PreAuthorize("@ss.hasPermi('credit:businessService:view')")
    @Log(title = "商品购买", businessType = BusinessType.INSERT)
    @PostMapping("/goods/purchase")
    public AjaxResult purchaseGoods(@RequestBody Map<String, Object> purchaseData)
    {
        Integer goodsId = (Integer) purchaseData.get("goodsId");
        Integer quantity = (Integer) purchaseData.get("quantity");
        String paymentMethod = (String) purchaseData.get("paymentMethod");
        String address = (String) purchaseData.get("address");
        
        // 模拟购买逻辑
        logger.info("用户购买商品，商品ID：{}，数量：{}，支付方式：{}，地址：{}", 
                   goodsId, quantity, paymentMethod, address);
        
        Map<String, Object> result = new HashMap<>();
        result.put("orderId", "G" + System.currentTimeMillis());
        result.put("status", "paid");
        result.put("message", "购买成功，商品将在24小时内发货");
        result.put("totalAmount", 7599);
        result.put("discount", 400);
        result.put("finalAmount", 7199);
        result.put("installments", paymentMethod.equals("installment") ? 12 : 1);
        
        return AjaxResult.success(result);
    }

    /**
     * 获取用户订单历史
     */
    @PreAuthorize("@ss.hasPermi('credit:businessService:view')")
    @GetMapping("/orders/history")
    public AjaxResult getOrderHistory(@RequestParam(required = false) String type)
    {
        List<Map<String, Object>> orders = new ArrayList<>();
        
        Map<String, Object> order1 = new HashMap<>();
        order1.put("orderId", "H20240125001");
        order1.put("type", "hotel");
        order1.put("title", "广州白云宾馆预订");
        order1.put("amount", 776);
        order1.put("status", "completed");
        order1.put("createTime", "2024-01-25 10:30:00");
        order1.put("creditDiscount", 82);
        orders.add(order1);
        
        Map<String, Object> order2 = new HashMap<>();
        order2.put("orderId", "G20240124001");
        order2.put("type", "goods");
        order2.put("title", "iPhone 15 Pro 购买");
        order2.put("amount", 7599);
        order2.put("status", "shipping");
        order2.put("createTime", "2024-01-24 14:20:00");
        order2.put("creditDiscount", 400);
        orders.add(order2);
        
        Map<String, Object> order3 = new HashMap<>();
        order3.put("orderId", "R20240123001");
        order3.put("type", "rental");
        order3.put("title", "市中心精装两室一厅租赁");
        order3.put("amount", 3500);
        order3.put("status", "active");
        order3.put("createTime", "2024-01-23 09:15:00");
        order3.put("creditDiscount", 500);
        orders.add(order3);
        
        return AjaxResult.success(orders);
    }

    // ======================== 普通用户专用接口（无权限） ========================

    /**
     * 获取用户信用信息（普通用户专用，无权限）
     */
    @GetMapping("/userCreditOpen")
    public AjaxResult getUserCreditOpen()
    {
        try {
            // 从数据库获取当前用户的真实信用信息
            Long userId = getUserId();
            CreditUserInfo userInfo = creditUserInfoService.selectCreditUserInfoByUserId(userId);
            
            Map<String, Object> userCredit = new HashMap<>();
            if (userInfo != null) {
                userCredit.put("creditScore", userInfo.getCreditScore());
                userCredit.put("creditLevel", getCreditLevel(userInfo.getCreditScore()));
                userCredit.put("canRent", userInfo.getCreditScore() >= 650);
                userCredit.put("canHotel", userInfo.getCreditScore() >= 600);
                userCredit.put("canGoods", userInfo.getCreditScore() >= 550);
                userCredit.put("discountRate", calculateDiscountRate(userInfo.getCreditScore()));
            } else {
                // 如果用户信息不存在，使用默认值
                userCredit.put("creditScore", 600);
                userCredit.put("creditLevel", "一般");
                userCredit.put("canRent", false);
                userCredit.put("canHotel", true);
                userCredit.put("canGoods", true);
                userCredit.put("discountRate", 5);
            }
            
            return AjaxResult.success(userCredit);
        } catch (Exception e) {
            return AjaxResult.error("获取用户信用信息失败：" + e.getMessage());
        }
    }

    /**
     * 获取租房服务列表（普通用户专用，无权限）
     */
    @GetMapping("/rental/listOpen")
    public AjaxResult getRentalListOpen(@RequestParam(required = false) String area,
                                       @RequestParam(required = false) String priceRange)
    {
        try {
            // 从数据库查询真实房源信息
            List<Map<String, Object>> roomList = new ArrayList<>();
            
            // 这里应该调用房源服务查询真实数据
            // 暂时使用模拟数据，但结构更真实
            Map<String, Object> room1 = new HashMap<>();
            room1.put("room_id", 1);
            room1.put("room_title", "精装两室一厅，采光良好");
            room1.put("room_address", "市中心CBD核心区域");
            room1.put("room_price", 3500.00);
            room1.put("room_area", 85.5);
            room1.put("room_type", "两室一厅");
            room1.put("required_score", 700);
            room1.put("room_images", "[\"https://images.unsplash.com/photo-1560448204-e02f11c3d0e2?w=400&h=300&fit=crop\", \"https://images.unsplash.com/photo-1560448204-603b3fc33ddc?w=400&h=300&fit=crop\"]");
            room1.put("room_desc", "精装修两室一厅，采光良好，交通便利，配套设施齐全");
            room1.put("facilities", Arrays.asList("空调", "热水器", "洗衣机", "冰箱"));
            room1.put("tags", Arrays.asList("地铁沿线", "精装修", "免押金"));
            roomList.add(room1);
            
            Map<String, Object> room2 = new HashMap<>();
            room2.put("room_id", 2);
            room2.put("room_title", "温馨一室户，拎包入住");
            room2.put("room_address", "地铁沿线，生活便利");
            room2.put("room_price", 2200.00);
            room2.put("room_area", 45.0);
            room2.put("room_type", "一室户");
            room2.put("required_score", 650);
            room2.put("room_images", "[\"https://images.unsplash.com/photo-1560448204-603b3fc33ddc?w=400&h=300&fit=crop\", \"https://images.unsplash.com/photo-1560448204-e02f11c3d0e2?w=400&h=300&fit=crop\"]");
            room2.put("room_desc", "温馨一室户，拎包入住，地铁沿线，生活便利");
            room2.put("facilities", Arrays.asList("空调", "热水器", "洗衣机"));
            room2.put("tags", Arrays.asList("地铁沿线", "拎包入住", "免押金"));
            roomList.add(room2);
            
            Map<String, Object> room3 = new HashMap<>();
            room3.put("room_id", 3);
            room3.put("room_title", "豪华三室两厅，景观房");
            room3.put("room_address", "江景豪宅区");
            room3.put("room_price", 5800.00);
            room3.put("room_area", 120.0);
            room3.put("room_type", "三室两厅");
            room3.put("required_score", 800);
            room3.put("room_images", "[\"https://images.unsplash.com/photo-1560448204-e02f11c3d0e2?w=400&h=300&fit=crop\", \"https://images.unsplash.com/photo-1560448204-603b3fc33ddc?w=400&h=300&fit=crop\"]");
            room3.put("room_desc", "豪华三室两厅，江景房，配套设施齐全");
            room3.put("facilities", Arrays.asList("空调", "热水器", "洗衣机", "冰箱", "电视", "宽带"));
            room3.put("tags", Arrays.asList("江景房", "豪华装修", "免押金"));
            roomList.add(room3);
            
            return AjaxResult.success(roomList);
        } catch (Exception e) {
            return AjaxResult.error("获取租房服务列表失败：" + e.getMessage());
        }
    }

    /**
     * 获取酒店服务列表（普通用户专用，无权限）
     */
    @GetMapping("/hotel/listOpen")
    public AjaxResult getHotelListOpen(@RequestParam(required = false) String city,
                                      @RequestParam(required = false) String checkIn,
                                      @RequestParam(required = false) String checkOut)
    {
        try {
            List<Map<String, Object>> hotelList = new ArrayList<>();
            
            Map<String, Object> hotel1 = new HashMap<>();
            hotel1.put("hotel_id", 1);
            hotel1.put("hotel_name", "希尔顿酒店");
            hotel1.put("hotel_address", "市中心商务区");
            hotel1.put("hotel_price", 688.00);
            hotel1.put("hotel_level", "五星级");
            hotel1.put("star", 5.0);
            hotel1.put("required_score", 750);
            hotel1.put("hotel_images", "[\"https://images.unsplash.com/photo-1566073771259-6a8506099945?w=400&h=300&fit=crop\", \"https://images.unsplash.com/photo-1571896349842-33c89424de2d?w=400&h=300&fit=crop\"]");
            hotel1.put("hotel_desc", "五星级酒店，商务设施齐全，服务一流");
            hotel1.put("amenities", Arrays.asList("免费WiFi", "健身房", "游泳池", "餐厅"));
            hotel1.put("tags", Arrays.asList("五星级", "免押金", "信用专享"));
            hotelList.add(hotel1);
            
            Map<String, Object> hotel2 = new HashMap<>();
            hotel2.put("hotel_id", 2);
            hotel2.put("hotel_name", "如家酒店");
            hotel2.put("hotel_address", "火车站附近");
            hotel2.put("hotel_price", 268.00);
            hotel2.put("hotel_level", "经济型");
            hotel2.put("star", 2.0);
            hotel2.put("required_score", 650);
            hotel2.put("hotel_images", "[\"https://images.unsplash.com/photo-1506744038136-46273834b3fb?w=400&h=300&fit=crop\"]");
            hotel2.put("hotel_desc", "经济型酒店，干净整洁，性价比高");
            hotel2.put("amenities", Arrays.asList("免费WiFi", "24小时前台"));
            hotel2.put("tags", Arrays.asList("经济型", "免押金", "信用专享"));
            hotelList.add(hotel2);
            
            Map<String, Object> hotel3 = new HashMap<>();
            hotel3.put("hotel_id", 3);
            hotel3.put("hotel_name", "万豪酒店");
            hotel3.put("hotel_address", "机场附近");
            hotel3.put("hotel_price", 988.00);
            hotel3.put("hotel_level", "五星级");
            hotel3.put("star", 5.0);
            hotel3.put("required_score", 800);
            hotel3.put("hotel_images", "[\"https://images.unsplash.com/photo-1512918728675-ed5a9ecdebfd?w=400&h=300&fit=crop\"]");
            hotel3.put("hotel_desc", "五星级酒店，机场附近，交通便利");
            hotel3.put("amenities", Arrays.asList("免费WiFi", "健身房", "游泳池", "餐厅", "商务中心"));
            hotel3.put("tags", Arrays.asList("五星级", "免押金", "信用专享"));
            hotelList.add(hotel3);
            
            return AjaxResult.success(hotelList);
        } catch (Exception e) {
            return AjaxResult.error("获取酒店服务列表失败：" + e.getMessage());
        }
    }

    /**
     * 获取商品服务列表（普通用户专用，无权限）
     */
    @GetMapping("/goods/listOpen")
    public AjaxResult getGoodsListOpen(@RequestParam(required = false) String category,
                                      @RequestParam(required = false) String priceRange)
    {
        try {
            List<Map<String, Object>> goodsList = new ArrayList<>();
            
            Map<String, Object> goods1 = new HashMap<>();
            goods1.put("goods_id", 1);
            goods1.put("goods_name", "iPhone 15 Pro");
            goods1.put("goods_category", "数码电子");
            goods1.put("goods_price", 7999.00);
            goods1.put("goods_images", "[\"https://images.unsplash.com/photo-1511707171634-5f897ff02aa9?w=400&h=300&fit=crop\"]");
            goods1.put("goods_desc", "最新款iPhone，性能强劲，信用分750以上专享价");
            goods1.put("recommend_score", 780);
            goods1.put("is_recommended", "1");
            goods1.put("stock_quantity", 50);
            goods1.put("is_available", "1");
            goods1.put("tags", Arrays.asList("信用分期", "免息", "限时优惠"));
            goodsList.add(goods1);
            
            Map<String, Object> goods2 = new HashMap<>();
            goods2.put("goods_id", 2);
            goods2.put("goods_name", "MacBook Air M2");
            goods2.put("goods_category", "数码电子");
            goods2.put("goods_price", 8999.00);
            goods2.put("goods_images", "[\"https://images.unsplash.com/photo-1517336714731-489689fd1ca8?w=400&h=300&fit=crop\"]");
            goods2.put("goods_desc", "轻薄笔记本，M2芯片，性能出色");
            goods2.put("recommend_score", 800);
            goods2.put("is_recommended", "1");
            goods2.put("stock_quantity", 30);
            goods2.put("is_available", "1");
            goods2.put("tags", Arrays.asList("信用分期", "免息", "限时优惠"));
            goodsList.add(goods2);
            
            Map<String, Object> goods3 = new HashMap<>();
            goods3.put("goods_id", 3);
            goods3.put("goods_name", "Nike Air Max 270");
            goods3.put("goods_category", "运动健身");
            goods3.put("goods_price", 899.00);
            goods3.put("goods_images", "[\"https://images.unsplash.com/photo-1519125323398-675f0ddb6308?w=400&h=300&fit=crop\"]");
            goods3.put("goods_desc", "经典跑鞋，舒适透气，信用用户免押金试穿");
            goods3.put("recommend_score", 720);
            goods3.put("is_recommended", "1");
            goods3.put("stock_quantity", 100);
            goods3.put("is_available", "1");
            goods3.put("tags", Arrays.asList("信用分期", "限时优惠"));
            goodsList.add(goods3);
            
            return AjaxResult.success(goodsList);
        } catch (Exception e) {
            return AjaxResult.error("获取商品服务列表失败：" + e.getMessage());
        }
    }

    /**
     * 获取商品推荐（普通用户专用，无权限）
     */
    @GetMapping("/goods/recommendOpen")
    public AjaxResult getGoodsRecommendOpen(@RequestParam(required = false) String category)
    {
        try {
            List<Map<String, Object>> recommendations = new ArrayList<>();
            
            Map<String, Object> rec1 = new HashMap<>();
            rec1.put("goods_id", 4);
            rec1.put("goods_name", "华为Mate 60 Pro");
            rec1.put("goods_category", "数码电子");
            rec1.put("goods_price", 6999.00);
            rec1.put("goods_images", "[\"https://images.unsplash.com/photo-1519125323398-675f0ddb6308?w=400&h=300&fit=crop\"]");
            rec1.put("goods_desc", "华为旗舰手机，性能强劲，拍照出色");
            rec1.put("recommend_score", 780);
            rec1.put("is_recommended", "1");
            rec1.put("stock_quantity", 40);
            rec1.put("is_available", "1");
            rec1.put("reason", "基于您的信用分780分，推荐此款旗舰手机");
            rec1.put("tags", Arrays.asList("信用专享", "旗舰体验"));
            recommendations.add(rec1);
            
            Map<String, Object> rec2 = new HashMap<>();
            rec2.put("goods_id", 5);
            rec2.put("goods_name", "AirPods Pro 2");
            rec2.put("goods_category", "数码电子");
            rec2.put("goods_price", 1799.00);
            rec2.put("goods_images", "[\"https://images.unsplash.com/photo-1517336714731-489689fd1ca8?w=400&h=300&fit=crop\"]");
            rec2.put("goods_desc", "降噪耳机，音质出色，便携性强");
            rec2.put("recommend_score", 720);
            rec2.put("is_recommended", "1");
            rec2.put("stock_quantity", 80);
            rec2.put("is_available", "1");
            rec2.put("reason", "您经常购买数码产品，这款耳机很适合您");
            rec2.put("tags", Arrays.asList("降噪", "信用优惠"));
            recommendations.add(rec2);
            
            Map<String, Object> rec3 = new HashMap<>();
            rec3.put("goods_id", 6);
            rec3.put("goods_name", "戴森V12无线吸尘器");
            rec3.put("goods_category", "生活用品");
            rec3.put("goods_price", 3690.00);
            rec3.put("goods_images", "[\"https://images.unsplash.com/photo-1511707171634-5f897ff02aa9?w=400&h=300&fit=crop\"]");
            rec3.put("goods_desc", "强劲吸力，信用分用户可享分期免息");
            rec3.put("recommend_score", 720);
            rec3.put("is_recommended", "1");
            rec3.put("stock_quantity", 25);
            rec3.put("is_available", "1");
            rec3.put("reason", "信用良好用户专享生活用品优惠");
            rec3.put("tags", Arrays.asList("生活", "信用专享"));
            recommendations.add(rec3);
            
            return AjaxResult.success(recommendations);
        } catch (Exception e) {
            return AjaxResult.error("获取商品推荐失败：" + e.getMessage());
        }
    }

    /**
     * 租赁房源（普通用户专用，无权限）
     */
    @Log(title = "租赁房源", businessType = BusinessType.INSERT)
    @PostMapping("/rentRoomOpen")
    public AjaxResult rentRoomOpen(@RequestBody Map<String, Object> rentData)
    {
        try {
            Integer roomId = (Integer) rentData.get("roomId");
            String checkInDate = (String) rentData.get("checkInDate");
            Integer months = (Integer) rentData.get("months");
            
            Map<String, Object> result = new HashMap<>();
            result.put("orderId", "RENT" + System.currentTimeMillis());
            result.put("status", "pending");
            result.put("message", "租赁申请已提交，请等待房东确认");
            result.put("estimatedTime", "24小时内");
            
            return AjaxResult.success(result);
        } catch (Exception e) {
            return AjaxResult.error("租赁申请失败：" + e.getMessage());
        }
    }

    /**
     * 预订酒店（普通用户专用，无权限）
     */
    @Log(title = "预订酒店", businessType = BusinessType.INSERT)
    @PostMapping("/bookHotelOpen")
    public AjaxResult bookHotelOpen(@RequestBody Map<String, Object> bookData)
    {
        try {
            Integer hotelId = (Integer) bookData.get("hotelId");
            String checkInDate = (String) bookData.get("checkInDate");
            String checkOutDate = (String) bookData.get("checkOutDate");
            Integer rooms = (Integer) bookData.get("rooms");
            
            Map<String, Object> result = new HashMap<>();
            result.put("orderId", "HOTEL" + System.currentTimeMillis());
            result.put("status", "confirmed");
            result.put("message", "酒店预订成功，无需支付押金");
            result.put("checkInTime", "14:00后");
            result.put("checkOutTime", "12:00前");
            
            return AjaxResult.success(result);
        } catch (Exception e) {
            return AjaxResult.error("酒店预订失败：" + e.getMessage());
        }
    }

    /**
     * 购买商品（普通用户专用，无权限）
     */
    @Log(title = "购买商品", businessType = BusinessType.INSERT)
    @PostMapping("/buyGoodsOpen")
    public AjaxResult buyGoodsOpen(@RequestBody Map<String, Object> buyData)
    {
        try {
            Integer goodsId = (Integer) buyData.get("goodsId");
            Integer quantity = (Integer) buyData.get("quantity");
            String paymentMethod = (String) buyData.get("paymentMethod");
            
            Map<String, Object> result = new HashMap<>();
            result.put("orderId", "GOODS" + System.currentTimeMillis());
            result.put("status", "processing");
            result.put("message", "商品购买成功，享受信用分期服务");
            result.put("installments", 12);
            result.put("monthlyPayment", 666.58);
            
            return AjaxResult.success(result);
        } catch (Exception e) {
            return AjaxResult.error("商品购买失败：" + e.getMessage());
        }
    }

    // 辅助方法
    private String getCreditLevel(Integer creditScore) {
        if (creditScore >= 800) return "优秀";
        else if (creditScore >= 750) return "良好";
        else if (creditScore >= 700) return "中等";
        else if (creditScore >= 650) return "一般";
        else return "较差";
    }
    
    private Integer calculateDiscountRate(Integer creditScore) {
        if (creditScore >= 800) return 20;
        else if (creditScore >= 750) return 15;
        else if (creditScore >= 700) return 10;
        else if (creditScore >= 650) return 5;
        else return 0;
    }
} 